package cn.fl.ref.mrgnmanageinfo.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.ref.fncprjpaysch.transform.FncPrjPaySchMVOTransform;
import cn.fl.ref.fncprjpaysch.vo.FncPrjPaySchMVO;
import cn.fl.ref.mrgnmanageinfo.service.IMrgnManageInfoService;
import cn.fl.ref.mrgnmanageinfo.transform.MrgnDetailInfoVOTransform;
import cn.fl.ref.mrgnmanageinfo.transform.MrgnManageInfoVOTransform;
import cn.fl.ref.mrgnmanageinfo.transform.MrgnTkOffInfoVOTransform;
import cn.fl.ref.mrgnmanageinfo.vo.MrgnDetailInfoVO;
import cn.fl.ref.mrgnmanageinfo.vo.MrgnManageInfoVO;
import cn.fl.ref.mrgnmanageinfo.vo.MrgnTkOffInfoVO;
import fl.flow.facade.flow.dto.FlowStartParamsDTO;
import fl.ref.fncprjpaysch.dto.FncPrjPaySchMDTO;
import fl.ref.mrgnmanageinfo.dto.MrgnDetailInfoDTO;
import fl.ref.mrgnmanageinfo.dto.MrgnManageInfoDTO;
import fl.ref.mrgnmanageinfo.dto.MrgnTkOffInfoDTO;
import fl.ref.mrgnmanageinfo.service.IMrgnManageInfoApiService;
/**
 * @Description: 保证金基础信息
 * @Description:业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 * 服务实现层
 */

@Service
public class MrgnManageInfoServiceImpl implements IMrgnManageInfoService {

	private static final Logger logger = LoggerFactory.getLogger(IMrgnManageInfoService.class);
	
	@Autowired
	private IMrgnManageInfoApiService  mrgnManageInfoApiService;

	@Override
	public Pager searchListPage(Pager page) throws BaseException {
		if(null == page)page = new Pager();
		return this.mrgnManageInfoApiService.searchListPage(page);
	}
	
	 @Override
	 public Long addMrgnDetail(MrgnDetailInfoVO entity) throws BaseException {
		if(null == entity){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		};
		//系统日志-有用户的情况下
		BaseLogUtils.info(logger, "add", "新增保证金流水信息数据.", CurrentThreadContext.getCurrentUserName());
			
		//系统日志-无用户的情况下
		BaseLogUtils.info(logger, "add", "新增保证金流水信息数据.");
		return this.mrgnManageInfoApiService.addMrgnDetail(MrgnDetailInfoVOTransform.toDTO(entity));
		}
	    
	 @Override
	 public List<MrgnDetailInfoVO> selectReturnInfoByPrjId(Long id) throws BaseException {
	     if(id==null||id==0){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		 };
		 List<MrgnDetailInfoDTO> dto = this.mrgnManageInfoApiService.selectReturnInfoByPrjId(id);
		 return MrgnDetailInfoVOTransform.toVOList(dto);
	}
	 
	 @Override
	 public List<MrgnTkOffInfoVO> selectDeductInfoByPrjId(Long id) throws BaseException {
	     if(id==null||id==0){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		 };
		 List<MrgnTkOffInfoDTO> dto = this.mrgnManageInfoApiService.selectDeductInfoByPrjId(id);
		 return MrgnTkOffInfoVOTransform.toVOList(dto);
	}
	 
	 @Override
	 public MrgnManageInfoVO selectPrjInfoByPrjId(Long id) throws BaseException {
	     if(id==null||id==0){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		 };
		 MrgnManageInfoDTO dto = this.mrgnManageInfoApiService.selectPrjInfoByPrjId(id);
		 return MrgnManageInfoVOTransform.toVO(dto);
	}
	 
	 @Override
	 public MrgnManageInfoVO selectPrjInfoByMgtLgcSn(Long id) throws BaseException {
	     if(id==null||id==0){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		 };
		 MrgnManageInfoDTO dto = this.mrgnManageInfoApiService.selectPrjInfoByMgtLgcSn(id);
		 return MrgnManageInfoVOTransform.toVO(dto);
	}

	@Override
	public boolean updateMrgnDetail(MrgnDetailInfoVO entity) throws BaseException {
		if(null == entity){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		};
		return this.mrgnManageInfoApiService.updateMrgnDetail(MrgnDetailInfoVOTransform.toDTO(entity));
	
	}

	@Override
	public MrgnDetailInfoVO selectCheckMrgnInfoById(Long id) throws BaseException {
		if(id==null||id==0){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		};
		MrgnDetailInfoDTO dto = this.mrgnManageInfoApiService.selectCheckMrgnInfoById(id);
		return MrgnDetailInfoVOTransform.toVO(dto);
	}
	
	@Override
	public boolean updateMrgnTkOffInfo(List<MrgnTkOffInfoVO> entityList) throws BaseException {
		if(entityList.size()<1){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		};
		return this.mrgnManageInfoApiService.updateMrgnTkOffInfo(MrgnTkOffInfoVOTransform.toDTOList(entityList));
	
	}
	
	 @Override
	 public Long addMrgnTkOffInfo(List<MrgnTkOffInfoVO> entityList) throws BaseException {
		if(entityList.size()<1){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		};
		//系统日志-有用户的情况下
		BaseLogUtils.info(logger, "addMrgnTkOffInfo", "新增保证金坐扣信息数据.", CurrentThreadContext.getCurrentUserName());
			
		//系统日志-无用户的情况下
		BaseLogUtils.info(logger, "addMrgnTkOffInfo", "新增保证金坐扣信息数据.");
		return this.mrgnManageInfoApiService.addMrgnTkOffInfo(MrgnTkOffInfoVOTransform.toDTOList(entityList));
	}

	@Override
	public List<MrgnTkOffInfoVO> getPrjPaySchInfoAdd(Long prjId) throws BaseException {
		List<MrgnTkOffInfoDTO> dtoList = this.mrgnManageInfoApiService.getPrjPaySchInfoAdd(prjId);
		return MrgnTkOffInfoVOTransform.toVOList(dtoList);
	}
	
	@Override
	public List<MrgnTkOffInfoVO> getPrjPaySchInfoUpdate(Long mgtLgcSn) throws BaseException {
		List<MrgnTkOffInfoDTO> dtoList = this.mrgnManageInfoApiService.getPrjPaySchInfoUpdate(mgtLgcSn);
		return MrgnTkOffInfoVOTransform.toVOList(dtoList);
	}

	@Override
	public List<MrgnTkOffInfoVO> getPrjPaySchInfoById(Long id) throws BaseException {
		if(id==null||id==0){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		 };
		 List<MrgnTkOffInfoDTO> dtoList = this.mrgnManageInfoApiService.getPrjPaySchInfoById(id);
		 return MrgnTkOffInfoVOTransform.toVOList(dtoList);
	}
	
	@Override
	public MrgnDetailInfoVO selectMrgnDetailInfo(Long lgcSn) throws BaseException {
		if(lgcSn==null||lgcSn==0){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		 };
		 MrgnDetailInfoDTO dto = this.mrgnManageInfoApiService.selectMrgnDetailInfo(lgcSn);
		 return MrgnDetailInfoVOTransform.toVO(dto);
	}
	
	@Override
	public FncPrjPaySchMVO selectRepayMainStByPrjId(Long id) throws BaseException {
		if(id==null||id==0){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		 };
		 FncPrjPaySchMDTO dto = this.mrgnManageInfoApiService.selectRepayMainStByPrjId(id);
		 return FncPrjPaySchMVOTransform.toVO(dto);
	}
	
	@Override
	public DataResultDTO addMrgnDeductFlowStart(FlowStartParamsDTO flowStartParamsDTO) throws BaseException{
		if(StringUtils.isEmpty(flowStartParamsDTO.getCrtUsrId()) || StringUtils.isEmpty(flowStartParamsDTO.getBusinessKey())){
			BaseLogUtils.info(logger, "addFlowStart", "用户ID和业务数据主键必须要存在!",CurrentThreadContext.getCurrentUserName());
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "用户ID和业务数据主键必须要存在!");
		}
		return this.mrgnManageInfoApiService.addMrgnDeductFlowStart(flowStartParamsDTO);
	}
	
	@Override
	public DataResultDTO addMrgnReturnFlowStart(FlowStartParamsDTO flowStartParamsDTO) throws BaseException{
		if(StringUtils.isEmpty(flowStartParamsDTO.getCrtUsrId()) || StringUtils.isEmpty(flowStartParamsDTO.getBusinessKey())){
			BaseLogUtils.info(logger, "addFlowStart", "用户ID和业务数据主键必须要存在!",CurrentThreadContext.getCurrentUserName());
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "用户ID和业务数据主键必须要存在!");
		}
		return this.mrgnManageInfoApiService.addMrgnReturnFlowStart(flowStartParamsDTO);
	}
	
}
